package com.yunheone.view.user;

import com.yunheone.mode.User;

import java.util.Scanner;

/**
 * Created by Administrator on 2017/8/8 0008.
 */
public class AddUser {
    public static User add(){
         System.out.println ("*********学员信息管理系统—添加用户*********");
        Scanner input=new Scanner ( System.in );
        System.out.println ("请输入要添加/修改的用户信息：");
        System.out.print ("请输入用户编号:");
        String id=input.next ();
        System.out.print("请输入用户名:");
        String Name=input.next ();
        System.out.print ("请输入真实姓名:");
        String valName=input.next ();
        System.out.print ("请输入用户密码:");
        String password=input.next ();
        System.out.print ("请输入用户类型(管理员/讲师):");
        try {
            String type = input.next ();
            if (!type.equals ( "管理员" )&&!type.equals ( "讲师" )){
               throw new Exception ( "用户类型输入有误，请重新输入" );
            }
            return new User ( id, Name, valName, password, type );
        } catch (Exception e){
            String message = e.getMessage ();
            System.out.println (message!=null ? message : "用户类型输入不合法,请重新输入");
            return add ();
        }
    }
}
